package com.xiaoxiong.mami.dao.mapper;

import com.xiaoxiong.mami.dao.daomain.UserToken;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface UserTokenMapper {
    @Delete({
        "delete from user_token",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into user_token (id, token, ",
        "userId, refreshToken, ",
        "expireTime, updateTime, ",
        "createTime)",
        "values (#{id,jdbcType=BIGINT}, #{token,jdbcType=VARCHAR}, ",
        "#{userId,jdbcType=VARCHAR}, #{refreshToken,jdbcType=VARCHAR}, ",
        "#{expireTime,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(UserToken record);

    @InsertProvider(type=UserTokenSqlProvider.class, method="insertSelective")
    int insertSelective(UserToken record);

    @Select({
        "select",
        "id, token, userId, refreshToken, expireTime, updateTime, createTime",
        "from user_token",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="token", property="token", jdbcType=JdbcType.VARCHAR),
        @Result(column="userId", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="refreshToken", property="refreshToken", jdbcType=JdbcType.VARCHAR),
        @Result(column="expireTime", property="expireTime", jdbcType=JdbcType.BIGINT),
        @Result(column="updateTime", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="createTime", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    UserToken selectByPrimaryKey(Long id);

    @UpdateProvider(type=UserTokenSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(UserToken record);

    @Update({
        "update user_token",
        "set token = #{token,jdbcType=VARCHAR},",
          "userId = #{userId,jdbcType=VARCHAR},",
          "refreshToken = #{refreshToken,jdbcType=VARCHAR},",
          "expireTime = #{expireTime,jdbcType=BIGINT},",
          "updateTime = #{updateTime,jdbcType=TIMESTAMP},",
          "createTime = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(UserToken record);
}